<template>
  <div id="app">
    <router-view />
  </div>
</template>

<script>
import { isNowDate } from "@/utils/common";
export default {
  name: "app",
  created() {
    this.init();
    // setAllScreen(false,document)
  },
  methods: {
    init() {
      let bgck = localStorage.getItem("bgck");
      if (!bgck)
        localStorage.setItem(
          "bgck",
          Math.floor(Math.random() * 0xffffff).toString(16)
        );

      let nowDate = localStorage.getItem("nowDate");
      let phoneGetCodeNK = {
        setPassword: {},
        transforPassword: {},
        resetPassword: {},
        register: {},
      };

      if (!nowDate) {
        localStorage.setItem("nowDate", +new Date());
        localStorage.setItem("phoneGetCodeNK", JSON.stringify(phoneGetCodeNK));
      } else {
        if (!isNowDate(Number(nowDate))) {
          localStorage.setItem("nowDate", +new Date());
          localStorage.setItem(
            "phoneGetCodeNK",
            JSON.stringify(phoneGetCodeNK)
          );
        }
      }
    },
  },
  // 以vue2为例
  mounted() {
    let userAgentInfo = window.navigator.userAgent;
    let Agents = new Array(
      "Android",
      "iPhone",
      "SymbianOS",
      "Windows Phone",
      "iPad",
      "iPod"
    );
    //pc
    console.log(userAgentInfo.toLowerCase(), "userAgentInfo.toLowerCase()");
    if (
      !Agents.some((item) =>
        userAgentInfo.toLowerCase().includes(item.toLowerCase())
      ) &&
      !(self.frameElement && self.frameElement.tagName == "IFRAME")
    ) {
      // 检查页面是否已经有iframe   这个判断让页面拥有只保留一个iframe
      let ifrTag = document.getElementsByTagName("iframe")[0];
      if (ifrTag) {
        // 如果有，则删除它
        ifrTag.remove();
      } else {
        let ifrTag = document.createElement("iframe");
        document.body.innerHTML = "";
        ifrTag.setAttribute("src", window.location.href);
        let styleObj = {
          width: "780px",
          height: "100vh",
          position: "absolute",
          left: "50%",
          transform: "translateX(-50%)",
        };
        Object.entries(styleObj).forEach(([key, value]) => {
          ifrTag.style[key] = value;
        });
        document.body.append(ifrTag);
      }
    }
  },
};
</script>

<style lang="less">
@import url("./assets/less/rest.less");
@import url("./assets/less/common.less");
</style>
